package com.lu.mediarecorder;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore;
import android.view.View;
import android.widget.VideoView;

import androidx.activity.result.contract.ActivityResultContracts;
import androidx.appcompat.app.AppCompatActivity;

import com.lu.mediarecorder.util.FileUtil;


/**
 * 使用系统自带的录像工具录制视频
 */
public class VideoViewActivity extends AppCompatActivity {

    private VideoView vvVideoView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_system_record);
        initView();
    }

    private void initView() {
        vvVideoView = findViewById(R.id.video);
    }

    public void systemCapture(View v) {
        Uri uri = Uri.fromFile(FileUtil.newMp4File());
        Intent intent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
        intent.putExtra(MediaStore.EXTRA_OUTPUT, uri);
        intent.putExtra(MediaStore.EXTRA_DURATION_LIMIT, 10);
        registerForActivityResult(new ActivityResultContracts.StartActivityForResult(), result -> {
            vvVideoView.setVideoURI(result.getData().getData());
            vvVideoView.start();
        }).launch(intent);
    }


}
